﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SmartSpace.News
{
    public class AssetSearcher : IAssetSearcher
    {
        public PagedResult<Asset> FindAssets(Guid categoryID, int start, int limit)
        {
            using (NewsDbContext context = new NewsDbContext())
            {
                List<Asset> assetList = context.Set<Asset>().Where(p => p.CategoryId == categoryID)
                     .OrderByDescending(p => p.CreateDate)
                     .Take(limit)
                     .Skip(start)
                     .ToList();
                int total = context.Set<Asset>().Where(p => p.CategoryId == categoryID).Count();

                return new PagedResult<Asset>(start, limit, total, assetList);
            }
        }
    }
}
